// components/top2/top2.js
const myBehavior = require("../../behaviors/requests")
Component({
  /**
   * 组件的属性列表
   */
  behaviors: [myBehavior],
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    base_urlstr: "https://logisticsengineering.gree.com",
    user_name: "",
    login_out_show: false,
    top_name: "是否确认切换用户？",
    task_count: 0,
  },

  /**
   * 组件的方法列表
   */
  attached() {
    this.getDatas()
    let name = wx.getStorageSync('name');
    if (name.length > 3) {
      let n = name.slice(0, 3) + ".."
      this.setData({
        user_name: n
      })
    } else {
      this.setData({
        user_name: name
      })
    }
    // this.getSelfData()
  },
  methods: {
    // 获取待办任务数据
    getDatas() {

      let url = this.data.base_urlstr + "/pfep2_api/personal_task_manage/query_current_total_task";
      let data = {
        page: 1,
        page_size: 1,
        query_cond: {
        },
        database: ""
      }
      this.post(url, data).then(res => {
        // console.log("获取待办任务数据1", res)


        if (res.code == 20000) {
          this.setData({
            task_count: res.data.total,
          })

        } else {
          this.setData({
            task_count: 0,
          })

        }
      }).catch(err => {
        if (err.code == '50001') {
          wx.showToast({
            title: err.msg,
            icon: 'none'
          })


          
        }
        this.setData({
          task_count: 0,
        })

      })



    },
    loginOut() {
      let name = wx.getStorageSync('name');

      let t = name + "，是否确认切换用户？"
      console.log(t);
      this.setData({
        login_out_show: true,
        top_name: t

      })
    },
    onConfirm() {
      wx.clearStorage()
      wx.reLaunch({
        url: '/pages/login1/login',
      });
    },
    onClose() {
      this.setData({
        login_out_show: false
      })
    },
    routeJump(e) {
      console.log(e.currentTarget.dataset.row_data);
      let key = e.currentTarget.dataset.row_data
      wx.navigateTo({
        url: key,
      })
    },
    routeJump1(e) {
      console.log(e.currentTarget.dataset.row_data);
      let key = e.currentTarget.dataset.row_data
      wx.navigateTo({
        url: '/packageB/pages/package/task_manager/task_manager?key=' + key,
      })
    },

  }
})
